<?php
/*
*
* -------------------------------------------------------
* CLASSNAME:        content
* GENERATION DATE:  29.04.2013
* CLASS FILE:       D:\wamp\www\webpros\webpros_sites\webpros\module-generator/generated-classes/class.content.inc.php
* FOR MYSQL TABLE:  content
* FOR MYSQL DB:     modulegenerator
* -------------------------------------------------------
* -------------------------------------------------------
*
*/

class content {
/**
*   @desc Variable Declaration with default value
*/
	private $_id;   // KEY ATTR. WITH AUTOINCREMENT
     private $_title;  
     private $_body;  
     private $_addeddate;  
     private $_updateddate;  
     private $_status;  
     
/**
*   @desc   CONSTRUCTOR METHOD
*/
	function __construct() {
		global $DBOBJ;
		$this->_obj = $DBOBJ;
		$this->_id = null; 
		$this->_title = null; 
		$this->_body = null; 
		$this->_addeddate = null; 
		$this->_updateddate = null; 
		$this->_status = null; 
	}

/**
*   @desc   DECONSTRUCTOR METHOD
*/
	function __destruct() {
		unset($this->_obj);
	}

/**
*   @desc   GETTER METHODS
*/

     public function getid() {
     	return $this->_id;
     }
     
     public function gettitle() {
     	return $this->_title;
     }
     
     public function getbody() {
     	return $this->_body;
     }
     
     public function getaddeddate() {
     	return $this->_addeddate;
     }
     
     public function getupdateddate() {
     	return $this->_updateddate;
     }
     
     public function getstatus() {
     	return $this->_status;
     }
     
/**
*   @desc   SETTER METHODS
*/

     public function setid($id) {
     	 $this->_id =  $id;
     }
     
     public function settitle($title) {
     	 $this->_title =  $title;
     }
     
     public function setbody($body) {
     	 $this->_body =  $body;
     }
     
     public function setaddeddate($addeddate) {
     	 $this->_addeddate =  $addeddate;
     }
     
     public function setupdateddate($updateddate) {
     	 $this->_updateddate =  $updateddate;
     }
     
     public function setstatus($status) {
     	 $this->_status =  $status;
     }
     
/**
*   @desc   SELECT METHOD / LOAD
*/

	public function select($id) {
		 $sql =  "SELECT * FROM `content` WHERE `id` = '". $id ."' ";
		 $row =  $this->_obj->select($sql); 

		 if (count($row) > 0) {
			 $this->_id = $row[0]['id'];
     		 $this->_title = $row[0]['title'];
     		 $this->_body = $row[0]['body'];
     		 $this->_addeddate = $row[0]['addeddate'];
     		 $this->_updateddate = $row[0]['updateddate'];
     		 $this->_status = $row[0]['status'];
     			 return $row[0];
		}else {
			 return;
		}
	}
/**
*   @desc   set All
*/
	 public function setAll($dataArray = array()) {
		 if (count($dataArray) <= 0) {
			return;
		}

		foreach ($dataArray as $key => $value) {
			$classKey = '_' . $key;
			$this->$classKey = $value;
		}
	}

/**
*   @desc   get All
*/

	 public function getAll($FORMAT = 'ARRAY') {
		$dataArray = new stdClass();
		$dataArray->id = $this->getid();
     	$dataArray->title = $this->gettitle();
     	$dataArray->body = $this->getbody();
     	$dataArray->addeddate = $this->getaddeddate();
     	$dataArray->updateddate = $this->getupdateddate();
     	$dataArray->status = $this->getstatus();
     	if ($FORMAT == 'ARRAY') {
			return (array) $dataArray;
		}
		return $dataArray;
	}
/**
*   @desc   COUNT
*/

	public function getCountcontent() {
		 $sql = "SELECT count(*) as cnt  FROM `content`";
		 $result = $this->_obj->select($sql);
		 return $result['0']['cnt'];
	}

/**
*   @desc   DELETE
*/
	public function delete($id) {
		 $sql = "DELETE FROM `content` WHERE `id` = '". $id ."'";
		 $result = $this->_obj->sql_query($sql);
	}

/**
*   @desc   INSERT
*/
	public function insert() {
		 $this->id = ""; // clear key for autoincrement
		 $sql = "INSERT INTO `content` ( `id`,`title`,`body`,`addeddate`,`updateddate`,`status` ) VALUES ( NULL,'".$this->_title."','".$this->_body."','".$this->_addeddate."','".$this->_updateddate."','".$this->_status."' )";
		 $result = $this->_obj->insert($sql);
		 return $result;
	}

/**
*   @desc   UPDATE
*/
	public function update($id) {
		 $sql = " UPDATE `content` SET  `id` = '".$this->_id."' , `title` = '".$this->_title."' , `body` = '".$this->_body."' , `addeddate` = '".$this->_addeddate."' , `updateddate` = '".$this->_updateddate."' , `status` = '".$this->_status."'  WHERE `id` =   '".$id."' ";
		 $result = $this->_obj->sql_query($sql);
	}
	public function getAllContentList($params = "*", $where = "", $orderby = "id", $limit = "") {
		$orderby = "ORDER BY " . $orderby;
		$sql = "SELECT " . $params . " FROM `content` a  " . $where . " " . $orderby . " " . $limit;
		$row = $this->_obj->select($sql);
		if ($row) {
			return $row;
		}
		return array();
	}
	
	public function performListAction($action = "", $ids = "''") {
		switch ($action) {
			case "delete":
				$sql = "DELETE FROM `content` WHERE `id` IN (" . $ids . ")";
			break;
			
			case "active":
				$sql = "UPDATE content SET  status = '1' WHERE `id` IN (" . $ids . ")";
			break;
			
			case "inactive":
				$sql = "UPDATE content SET  status = '0' WHERE `id` IN (" . $ids . ")";
			break;
			
			default:
				$sql = "";
		}
		if ($sql == "") {
			return false;
		}
		$result = $this->_obj->sql_query($sql);
		return true;
    }
	
	public function checkContentExists($title) {
		$sql = "select * from `content` where title = '" . $title . "' limit 1";
		$row = $this->_obj->select($sql);
		if ($row) {
			return true;
		}
		return false;
	}
	
	

} 
?>